﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Marmat.Forms.Skin
{
    partial class Form
    {
        /// <summary>
        /// 点击标题创建的菜单
        /// </summary>
        [Category("Skin")]
        public ContextMenuStrip CaptionContextMenu { get; set; }

        /// <summary>
        /// 显示标题的菜单
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        protected void OnCaptionContextMenu(int x, int y)
        {
            if (this.CaptionContextMenu != null)
                this.CaptionContextMenu.Show(x, y);
        }

        /// <summary>
        /// 设置或返回关闭按钮的皮肤图片。
        /// </summary>
        [Category("Skin"), Description("设置或返回关闭按钮的皮肤图片。")]
        [Browsable(false), Localizable(true), EditorBrowsable(EditorBrowsableState.Always)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), TypeConverter(typeof(FormConverter))]
        public FormButton CloseButtonImage
        {
            get
            {
                if (_CloseButtonImage is null)
                {
                    _CloseButtonImage = new FormButton();
                    _CloseButtonImage.ToolTip = "关闭";
                }
                return _CloseButtonImage;
            }
        }
        FormButton _CloseButtonImage;

        /// <summary>
        /// 设置或返回最大化按钮的皮肤图片。
        /// </summary>
        [Category("Skin"), Description("设置或返回最大化按钮的皮肤图片。")]
        [Browsable(false), Localizable(true), EditorBrowsable(EditorBrowsableState.Always)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), TypeConverter(typeof(FormConverter))]
        public FormButton MaximumButtonImage
        {
            get
            {
                if (_MaximumButtonImage is null)
                {
                    _MaximumButtonImage = new FormButton();
                    _MaximumButtonImage.ToolTip = "最大化";
                }
                return _MaximumButtonImage;
            }
        }
        FormButton _MaximumButtonImage;

        /// <summary>
        /// 设置或返回恢复默认大小按钮的皮肤图片。
        /// </summary>
        [Category("Skin"), Description("设置或返回恢复默认大小按钮的皮肤图片。")]
        [Browsable(false), Localizable(true), EditorBrowsable(EditorBrowsableState.Always)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), TypeConverter(typeof(FormConverter))]
        public FormButton RestoreButtonImage
        {
            get
            {
                if (_RestoreButtonImage is null)
                {
                    _RestoreButtonImage = new FormButton();
                    _RestoreButtonImage.ToolTip = "还原";
                }
                return _RestoreButtonImage;
            }
        }
        FormButton _RestoreButtonImage;

        /// <summary>
        /// 设置或返回最小化按钮的皮肤图片。
        /// </summary>
        [Category("Skin"), Description("设置或返回最小化按钮的皮肤图片。")]
        [Browsable(false), Localizable(true), EditorBrowsable(EditorBrowsableState.Always)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), TypeConverter(typeof(FormConverter))]
        public FormButton MinimumButtonImage
        {
            get
            {
                if (_MinimumButtonImage is null)
                {
                    _MinimumButtonImage = new FormButton();
                    _MinimumButtonImage.ToolTip = "最小化";
                }
                return _MinimumButtonImage;
            }
        }
        FormButton _MinimumButtonImage;

        /// <summary>
        /// 设置或返回帮助按钮的皮肤图片。
        /// </summary>
        [Category("Skin"), Description("设置或返回帮助按钮的皮肤图片。")]
        [Browsable(false), Localizable(true), EditorBrowsable(EditorBrowsableState.Always)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), TypeConverter(typeof(FormConverter))]
        public FormButton HelpButtonImage
        {
            get
            {
                if (_HelpButtonImage is null)
                {
                    _HelpButtonImage = new FormButton();
                    _HelpButtonImage.ToolTip = "帮助";
                }
                return _HelpButtonImage;
            }
        }
        FormButton _HelpButtonImage;

        /// <summary>
        /// 是否绘制客户端区域
        /// </summary>
        [DefaultValue(false)]
        [Category("Skin"), Description("设置或返回帮助按钮的皮肤图片。")]
        public bool DrawClientArea { get; set; } = false;

        /// <summary>
        /// 获取或设置一个值，该值指示显示 Form 时是否出现三维阴影效果。
        /// </summary>
        [DefaultValue(false)]
        [Category("Skin"), Description("获取或设置一个值，该值指示显示 Form 时是否出现三维阴影效果。")]
        public bool DropShadowEnabled
        {
            get => _dropShadowEnabled;
            set
            {
                if (!this.DesignMode && this._dropShadowEnabled != value)
                    SetClassLong(this.Handle, GCL_STYLE, GetClassLong(value ? this.Handle : IntPtr.Zero, GCL_STYLE) | CS_DropSHADOW);
                _dropShadowEnabled = value;
            }
        }
        bool _dropShadowEnabled;

        /// <summary>
        /// 获取或设置窗口的系统按钮。
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Always), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [Localizable(true), NotifyParentProperty(true), Category("Skin"), Description("获取或设置窗口的系统按钮。")]
        public List<FormButton> FormButtonCollection { get; } = new List<FormButton>();

        /// <summary>
        /// 获取或设置一个值，该值指示显示 Form 的图片皮肤。
        /// </summary>
        [Browsable(true)]
        [Category("Skin")]
        [Description("获取或设置一个值，该值指示显示 Form 的图片皮肤。")]
        [DefaultValue(false)]
        public Image SkinBackgroundImage
        {
            get => m_SkinBackgroundImage;
            set
            {
                m_SkinBackgroundImage = value;
                this.DrawCaption(this.Handle, FormMouseState.None);
                this.Invalidate();
            }
        }
        private Image m_SkinBackgroundImage;
    }
}
